from tedtree import TEDTree
from displaytree import DisplayTree
from node import Node
from generatetree import GenerateTree
import random

class Program:

    def __init__(self):
        self.generator = GenerateTree(10, 10, 10, 50, 20)
        self.size = 20
        self.originals = 10
        self.changedTrees = 10
        self.TEDTree = TEDTree("C:\Users\Charles\Documents\jira-reporting\Thesis\Trees")
        self.generator.getOrdered()
        display = DisplayTree()
        trees = []
        symbols = []
        originalCount = 0
        for symbol in range(0,100):
            symbols.append(str(random.randint(0,100)))
        for i in range(0, self.originals):
            size = random.randint(1,self.size)
            tree = self.generator.getTreeOrdered(size, symbols)
            display.getTree(tree, "original_%d.png" % originalCount)
            original = tree
            originalCount = originalCount + 1
            count = 0
            for x in range(0, self.changedTrees):
                tree = self.generator.getTreeOrdered(size, symbols)
                trees.append(tree)
                display.getTree(tree, "compare_%d_%d.png" % (originalCount, count))
                count = count + 1
            self.createComparisons(original, trees)
            #self.getResultsBinary()
        return

    def createComparisons(self, original, trees):
        count = 0
        for tree in trees:
            filenameOriginal = "test" + str(count) + "F.txt"
            self.TEDTree.createBinaryTree(original, filenameOriginal)
            filenameCompare = "test" + str(count) + "G.txt"
            self.TEDTree.createBinaryTree(tree, filenameCompare)
            count = count + 1

    def getResultsBinary(self):
        results = []
        trees = self.TEDTree.findFilesBinary()
        for comparison in trees.keys():
            original = trees[comparison]["original"]
            compare = trees[comparison]["compare"]
            results.append(Compare(original, compare).rotation_distance())
            print results
        print results
        return




if __name__ == "__main__":
    Program()
